package com.zznzzn.myweb.service;

import com.zznzzn.myweb.exceptions.ServiceException;
import com.zznzzn.myweb.mapper.ReceivingMapper;
import com.zznzzn.myweb.pojo.Receiving;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReceivingServiceImpl implements ReceivingService {
    @Autowired
    private ReceivingMapper mapper;


    @Override
    public int addReceiving(Receiving receiving) {

        if( mapper.addReceiving(receiving) != 0){
            return 1;
        }else{
            throw new ServiceException("增加收件地址失败");
        }
    }

    @Override
    public List<Receiving> getReceivingByUid(String uuid) {
        return mapper.queryAllReceivingByUser(uuid);
    }

    @Override
    public int updateReceiving(Receiving receiving) {
        if( mapper.updateReceiving(receiving) != 0){
            return 1;
        }else{
            throw new ServiceException("修改收件地址失败");
        }
    }

    @Override
    public int deleteReceiving(String receid) {
        if( mapper.deleteReceiving(receid) != 0){
            return 1;
        }else{
            throw new ServiceException("删除收件地址失败");
        }
    }

    @Override
    public int getReceCount(String uuid) {
        return mapper.getReceCount(uuid);
    }
}
